"""
安装python包
"""

import subprocess
import sys


def install_package(package_name: str) -> dict:
    try:
        res = subprocess.run(
            [sys.executable, "-m", "pip", "install", package_name],
            capture_output=True, text=True
        )
        result = {
            "success": (res.stderr == ''),
            "info": res.stdout,
            "error": res.stderr
        }
        return result
    except subprocess.CalledProcessError as e:
        result = {
            "success": False,
            "info": f"pip安装 {package_name} 失败.",
            "error": str(e)
        }
        return result